const mongoose = require('mongoose')
const moment = require('moment')

const Comment = mongoose.model('Comment')


const latestcomments = () =>
  Comment.find({},{name:1,comment:1,timestamp:1,_id:0}).sort({timestamp:-1}).limit(1)
  .then(([res]) => ({
      name: res ? res.name : null,
      comment: res ? res.comment :null,
      timestamp: res ? moment(res.timestamp).format('MMMM Do YYYY, h:mm:ss a') :null,
  }))


module.exports = latestcomments
